<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>折扣信息</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="robots" content="all,follow">
    <!-- Bootstrap CSS-->
    <link rel="stylesheet" href="vendor/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome CSS-->
    <link rel="stylesheet" href="vendor/font-awesome/css/font-awesome.min.css">
    <!-- Fontastic Custom icon font-->
    <link rel="stylesheet" href="css/fontastic.css">
    <!-- Google fonts - Poppins -->
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Poppins:300,400,700">
    <!-- theme stylesheet-->
    <link rel="stylesheet" href="css/style.default.css" id="theme-stylesheet">
    <!-- Custom stylesheet - for your changes-->
    <link rel="stylesheet" href="css/custom.css">
    <!-- Favicon-->
    <link rel="shortcut icon" href="img/favicon.ico">
    <!-- Tweaks for older IEs--><!--[if lt IE 9]>
    <script src="js/template/html15shiv.js"></script>
    <script src="js/template/respond.js"></script>
    <![endif]-->
    <!-- 开发环境版本，包含了有帮助的命令行警告 -->
    <script src="js/template/vue.js"></script>
    <script src="js/template/axios.js"></script>
    <link href="css/bootstrap.css">
    <script src="js/template/jquery.js"></script>
    <script src="js/template/bootstrap.js"></script>
    <!-- JavaScript files-->
    <script src="/vendor/jquery/jquery.min.js"></script>
    <script src="/vendor/popper.js/umd/popper.min.js"> </script>
    <script src="/vendor/bootstrap/js/bootstrap.min.js"></script>
    <script src="/vendor/jquery.cookie/jquery.cookie.js"> </script>
    <script src="/vendor/jquery-validation/jquery.validate.min.js"></script>
    <!-- Main File-->
    <script src="/js/front.js"></script>

    <style>
        .input-group{
            margin-bottom: 10px;
        }

    </style>

</head>

<body>

<div class="page" >
    <!-- Main Navbar-->
    <header class="header">
        <nav class="navbar">
            <!-- Search Box-->
            <div class="search-box">
                <button class="dismiss"><i class="icon-close"></i></button>
                <form id="searchForm" action="#" role="search">
                    <input type="search" placeholder="What are you looking for..." class="form-control">
                </form>
            </div>
            <div class="container-fluid">
                <div class="navbar-holder d-flex align-items-center justify-content-between">
                    <!-- Navbar Header-->
                    <div class="navbar-header">
                        <!-- Navbar Brand --><a href="index.html" class="navbar-brand d-none d-sm-inline-block">
                        <!-- 这里可以接受数据改成客户的标题 -->
                        <div class="brand-text d-none d-lg-inline-block"><span>太平洋影城 </span><strong>后台管理系统</strong></div>
                        <div class="brand-text d-none d-sm-inline-block d-lg-none"><strong>后台管理系统</strong></div></a>
                        <!-- Toggle Button--><a id="toggle-btn" href="#" class="menu-btn active"><span></span><span></span><span></span></a>
                    </div>
                    <!-- Navbar Menu -->
                    <ul class="nav-menu list-unstyled d-flex flex-md-row align-items-md-center">
                        <!-- Notifications-->
                        <li class="nav-item dropdown" id="header_notification">
                            <a id="notifications" rel="nofollow" data-target="#" href="javascript:void(0)" data-toggle="dropdown"  class="nav-link"><i class="fa fa-bell-o"></i></a>
                            <ul aria-labelledby="notifications" class="dropdown-menu">
                                <li><a rel="nofollow" href="#" class="dropdown-item">
                                    <div class="notification">
                                        <div class="notification-content"><i class="fa fa-envelope bg-green"></i>You have 6 new messages </div>
                                        <div class="notification-time"><small>4 minutes ago</small></div>
                                    </div></a></li>
                                <li><a rel="nofollow" href="#" class="dropdown-item">
                                    <div class="notification">
                                        <div class="notification-content"><i class="fa fa-twitter bg-blue"></i>You have 2 followers</div>
                                        <div class="notification-time"><small>4 minutes ago</small></div>
                                    </div></a></li>
                                <li><a rel="nofollow" href="#" class="dropdown-item">
                                    <div class="notification">
                                        <div class="notification-content"><i class="fa fa-upload bg-orange"></i>Server Rebooted</div>
                                        <div class="notification-time"><small>4 minutes ago</small></div>
                                    </div></a></li>
                                <li><a rel="nofollow" href="#" class="dropdown-item">
                                    <div class="notification">
                                        <div class="notification-content"><i class="fa fa-twitter bg-blue"></i>You have 2 followers</div>
                                        <div class="notification-time"><small>10 minutes ago</small></div>
                                    </div></a></li>
                                <li><a rel="nofollow" href="#" class="dropdown-item all-notifications text-center"> <strong>view all notifications                                            </strong></a></li>
                            </ul>
                        </li>
                        <!-- Logout -->
                        <li class="nav-item"><a href="login.html" class="nav-link logout"> <span class="d-none d-sm-inline">登出</span><i class="fa fa-sign-out"></i></a></li>
                    </ul>
                </div>
            </div>
        </nav>
    </header>

    <div class="page-content d-flex align-items-stretch">
        <!-- 引出公用的sidebar -->
        <nav class="side-navbar common_sidebar">
            <!-- Side Navbar -->
            <!-- Sidebar Header-->
            <div class="sidebar-header d-flex align-items-center">
                <div class="title">
                    <h1 class="h4">商家名</h1>
                </div>
            </div>
            <!-- Sidebar Navidation Menus--><span class="heading">影院设置</span>
            <ul class="list-unstyled">
                <li class="" id="consoleSidebar" onclick="consoleSidebar()"><a href="index.html"> <i class="icon-home"></i>控制台 </a></li>
                <li id="scheduleSidebar" onclick="scheduleSidebar()"><a href="schedule.html"> <i class="icon-padnote"></i>排片 </a></li>
                <li class="active"><a href="level.html"> <i class="icon-interface-windows"></i></i>VIP设置</a></li>
                <li> <a href="payment.html"> <i class="icon-screen"></i>收款信息 </a></li>
            </ul><span class="heading">统计与服务</span>
            <ul class="list-unstyled">
                <li> <a href="statistics.html"> <i class="icon-flask"></i>营业额统计 </a></li>
                <li> <a href="#"> <i class="icon-mail"></i> 服务反馈 </a></li>
            </ul>
        </nav>
        <div class="content-inner" v-if="levels!=null">
            <!-- Page Header-->
            <header class="page-header">
                <div class="container-fluid" >
                    <h2 class="no-margin-bottom">vip设置</h2>
                </div>
                <div class="container" style="margin-top:10px ">
                    <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addModal">添加等级</button>
                </div>
            </header>

            <div class="container">
                <table class="table table-hover" style="position: relative;left: 10px;">
                    <thead>
                    <tr>
                        <th>vip等级</th>
                        <th>最小积分</th>
                        <th>最大积分</th>
                        <th>折扣</th>
                        <th>操作</th>

                    </tr>
                    </thead>
                    <tbody id="level_tr" >
                    <tr  v-for="level in levels">
                        <td>{{level.level_name}}</td>
                        <td>{{level.min_score}}</td>
                        <td>{{level.max_score}}</td>
                        <td>{{level.discount}}</td>
                        <td><a  style="cursor: pointer"  data-toggle="modal" data-target="#updateModal" :onclick="'getId('+level.level_id+')'"><span  class ="glyphicon glyphicon-pencil" ></span></a>
                            <a  style="cursor: pointer" ><span class ="glyphicon glyphicon-trash" :onclick="'deleteLevel('+level.level_id+')'"></span></a></td>
                    </tr>
                    </tbody>
                </table>
            </div>

            <!-- Page Footer-->
            <footer class="main-footer">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-sm-6">
                            <p>Copyright &copy; 2019.Company name All rights reserved.More Templates <a href="http://www.cssmoban.com/" target="_blank" title="模板之家">${cinema.name}</a>  <a href="http://www.cssmoban.com/" title="网页模板" target="_blank"></a></p>
                        </div>
                        <div class="col-sm-6 text-right">
                            <p></p>
                        </div>
                    </div>
                </div>
            </footer>
        </div>
    </div>
    <!--添加vip 模态框（Modal） -->
    <div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"  >
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title" id="myModalLabel">添加vip信息</h4>
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                </div>
                <div class="modal-body">
                    <div style="padding: 10px 20px 10px;">
                        <form class="bs-example bs-example-form" role="form">

                            <div class="input-group">
                                <span class="input-group-addon">vip等级</span>
                                <input type="text" class="form-control" placeholder="" id="add_level_name">
                            </div>
                            <div class="input-group">
                                <span class="input-group-addon">最小积分</span>
                                <input type="text" class="form-control" placeholder="" id="add_min_score">
                            </div>
                            <div class="input-group">
                                <span class="input-group-addon">最大积分</span>
                                <input type="text" class="form-control" placeholder="" id="add_max_score">
                            </div>
                            <div class="input-group"><p>折扣:  </p>
                                <select id="add_discount">
                                    <option value ="volvo" >1.00</option>
                                    <option value ="saab">0.95</option>
                                    <option value="opel">0.90</option>
                                    <option value="audi">0.85</option>
                                    <option value="audi">0.80</option>
                                    <option value="audi">0.75</option>
                                    <option value="audi">0.70</option>
                                    <option value="audi">0.65</option>
                                    <option value="audi">0.60</option>
                                    <option value="audi">0.55</option>
                                    <option value="audi">0.50</option>
                                    <option value="audi">0.45</option>
                                    <option value="audi">0.40</option>
                                    <option value="audi">0.35</option>
                                    <option value="audi">0.30</option>
                                    <option value="audi">0.25</option>
                                    <option value="audi">0.20</option>
                                    <option value="audi">0.15</option>
                                    <option value="audi">0.10</option>
                                    <option value="audi">0.05</option>
                                    <option value="audi">0.00</option>
                                </select>
                            </div>
                        </form>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="addLevel()">提交信息</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div>
    <!--修改vip 模态框（Modal） -->
    <div class="modal fade" id="updateModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"  >
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title" id="">vip信息修改</h4>
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                </div>
                <div class="modal-body">
                    <div style="padding: 10px 20px 10px;">
                        <form class="bs-example bs-example-form" role="form">

                            <div class="input-group">
                                <span class="input-group-addon">vip等级</span>
                                <input type="text" class="form-control" placeholder="" id="update_level_name">
                            </div>
                            <div class="input-group">
                                <span class="input-group-addon">最小积分</span>
                                <input type="text" class="form-control" placeholder="" id="update_min_score">
                            </div>
                            <div class="input-group">
                                <span class="input-group-addon">最大积分</span>
                                <input type="text" class="form-control" placeholder="" id="update_max_score">
                            </div>
                            <div class="input-group"><p>折扣:  </p>
                                <select id="update_discount">
                                    <option value ="volvo" >1.00</option>
                                    <option value ="saab">0.95</option>
                                    <option value="opel">0.90</option>
                                    <option value="audi">0.85</option>
                                    <option value="audi">0.80</option>
                                    <option value="audi">0.75</option>
                                    <option value="audi">0.70</option>
                                    <option value="audi">0.65</option>
                                    <option value="audi">0.60</option>
                                    <option value="audi">0.55</option>
                                    <option value="audi">0.50</option>
                                    <option value="audi">0.45</option>
                                    <option value="audi">0.40</option>
                                    <option value="audi">0.35</option>
                                    <option value="audi">0.30</option>
                                    <option value="audi">0.25</option>
                                    <option value="audi">0.20</option>
                                    <option value="audi">0.15</option>
                                    <option value="audi">0.10</option>
                                    <option value="audi">0.05</option>
                                    <option value="audi">0.00</option>
                                </select>
                            </div>
                        </form>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal" id="update_closeBtn">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="updateLevel()" id="updateBtn">提交信息</button>

                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div>


</div>



<!-- JavaScript files-->
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/popper.js/umd/popper.min.js"> </script>
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="vendor/jquery.cookie/jquery.cookie.js"> </script>
<script src="vendor/jquery-validation/jquery.validate.min.js"></script>

<script src="js/front.js"></script>

<script>
    $(function() {
        // 先刷新一次前端
        getMsg();

        // 虽然有点蠢 但是能实现实时刷新
        var ref = setInterval(function(){
            getMsg();
        },15*1000);

        function getMsg() {
            $.ajax({
                url: "/customerbackend/getNotifyMsg",
                data: {
                    db: "filmforcustomer"
                },
                type: "get",
                success: function (data) {
                    var content = "";
                    if (data.length == 0) {
                        content += "<a id=\"notifications\" rel=\"nofollow\" data-target=\"#\" href=\"javascript:void(0)\" data-toggle=\"dropdown\"  class=\"nav-link\"><i class=\"fa fa-bell-o\"></i></a>\n" +
                            "                        <ul aria-labelledby=\"notifications\" class=\"dropdown-menu\">\n" +
                            "                            <li><a rel=\"nofollow\" href=\"#\" class=\"dropdown-item\">\n" +
                            "                                <div class=\"notification\">\n" +
                            "                                    <div class=\"notification-content\"><i class=\"fa fa-envelope bg-green\"></i> 没有未读的新订单信息 </div>\n" +
                            "                                    <div class=\"notification-time\"><small></small></div>\n" +
                            "                                </div></a></li>\n" +
                            "                        </ul>"
                    } else {
                        content += "<a id=\"notifications\" rel=\"nofollow\" data-target=\"#\" href=\"javascript:void(0)\" data-toggle=\"dropdown\"  class=\"nav-link\"><i class=\"fa fa-bell-o\" onclick=\"readMsg()\"></i><span class=\"badge bg-red badge-corner\">" + data.length + "</span></a>\n";
                        content += "                        <ul aria-labelledby=\"notifications\" class=\"dropdown-menu\">\n";
                        for (var i = 0; i < data.length; i++) {
                            var temp = data[i].split("：")
                            content +=
                                "                            <li><a rel=\"nofollow\" href=\"#\" class=\"dropdown-item\">\n" +
                                "                                <div class=\"notification\">\n" +
                                "                                    <div class=\"notification-content\"><i class=\"fa fa-envelope bg-green\"></i>" + temp[0] + "</div>\n" +
                                "                                    <div class=\"notification-time\"><small>" + temp[1] + "</small></div>\n" +
                                "                                </div></a></li>\n";
                        }
                        content += "                        </ul>";
                    }
                    $("#header_notification").html(content);
                }
            });

        }
    })

    function readMsg() {
        $.ajax({
            url: "/customerbackend/readNotifyMsg",
            data: {
                db: "filmforcustomer"
            },
            type: "get",
            success: function (data) {
                console.log("已阅读所有信息")
            }
        })
    }
</script>

<script type = "text/javascript">
    //展示所有vip信息
    $(function () {
        listLevels();
        //$(".common_header").load('_header.html');
        //$(".common_sidebar").load('_sidebar.html');
    })
    function listLevels() {
    new Vue({
        el: '.page',
        data () {
            return {
                levels: null
            }
        },
        mounted () {
            axios
                .get('http://localhost:8788/customerbackend/levels')
                .then(response => (this.levels = response.data.data))
                .catch(function (error) { // 请求失败处理
                    console.log(error);
                });
        }
    })

    }
    // 添加level
    function addLevel() {
        var level_name=$("#add_level_name").val();
        var min_score=$("#add_min_score").val();
        var max_score=$("#add_max_score").val();
        var discount= $("#add_discount option:selected").text();
        const params = new URLSearchParams();
        params.append('level_name',level_name );
        params.append('min_score',min_score );
        params.append('max_score',max_score );
        params.append('discount',discount);
        new Vue({
            el: '#addModal',
            mounted() {
                axios.post('http://localhost:8788/customerbackend/levels',params)
                    .then(function (response) {
                        alert(response.data.msg);
                        location.reload();
                    })
                    .catch(function (error) {
                        console.log(error);
                        alert("添加失败")
                    })
            }
        })
    }
    //获取当前id
    function getId(level_id) {
        document.getElementById("updateBtn").value=level_id;
    }
    // 修改level
    function updateLevel() {
        var level_id=$("#updateBtn").val();
        var level_name=$("#update_level_name").val();
        var min_score=$("#update_min_score").val();
        var max_score=$("#update_max_score").val();
        var discount= $("#update_discount option:selected").text();
        const params = new URLSearchParams();
        params.append('level_id',level_id );
        params.append('level_name',level_name );
        params.append('min_score',min_score );
        params.append('max_score',max_score );
        params.append('discount',discount);
        new Vue({
            el: '#updateModal',
            mounted() {
                axios.put('http://localhost:8788/customerbackend/levels',params)
                    .then(function (response) {
                        alert(response.data.msg);
                        location.reload();
                    })
                    .catch(function (error) {
                        console.log(error);
                        alert("修改失败")
                    })
            }
        })
    }

    //删除level
    function deleteLevel(level_id) {

        new Vue({
            el: '#updateModal',
            mounted() {
                axios.delete('http://localhost:8788/customerbackend/levels?level_id='+level_id)
                    .then(function (response) {
                        alert(response.data.msg);
                        location.reload();
                    })
                    .catch(function (error) {
                        console.log(error);
                        alert("删除失败")
                    })
            }
        })
    }

</script>

</body>

</html>